<tagLib name="strends" />
<include file="Public:header" />
<div class="handle-btns">
	<strends:linkBtn text="{%RETURN_LIST}" href="{:Cookie::get('returnUrl')}" />
</div>
<form method='post' id="form" name="form" action="{:U(MODULE_NAME.'/update')}" enctype="multipart/form-data">
<table cellpadding="4" cellspacing="0" border="0" class="table-form">
	<tr>
		<th width="150">{%NAME}</th>
		<td><input type="text" class="textinput requireinput" name="title" value="{$vo.title}" /></td>
	</tr>
	<tr>
		<th>{%PARENT_ID}</th>
		<td>
			<strends:select id='pid' name='pid' first='{%ROOT_ID}' selected="vo['pid']" textfield='title' valuefield='id' options='cate_list' />
		</td>
	</tr>
	<tr>
		<th>{%GTYPE}</th>
		<td>
			<select name="gtype" onchange="changGtype(this);">
				<option value="1" <if condition="$vo.gtype eq 1">selected</if>>{%TYPE_1}</option>
				<option value="2" <if condition="$vo.gtype eq 2">selected</if>>{%TYPE_2}</option>
				<option value="3" <if condition="$vo.gtype eq 3">selected</if>>{%TYPE_3}</option>
				<option value="4" <if condition="$vo.gtype eq 4">selected</if>>{%TYPE_4}</option>
			</select>
		</td>
	</tr>	
	<tr>
		<th>{%IS_ALL}</th>
		<td>
			<input type="checkbox" name="is_all" id="is_all" value="1" <if condition="$vo.is_all eq 1">checked</if>>回复全部
		</td>
	</tr>
	<tr>
		<th>{%SORT}</th>
		<td>
			<input type="text" class="textinput" name="sort" value="{$vo.sort}" />
		</td>
	</tr>
	<tr class="url" <if condition="$vo.gtype neq 1">style="display:none;"</if>>
		<th>{%URL}</th>
		<td><input type="text" class="textinput requireinput" name="url" value="{$vo.url}" size="60"/></td>
	</tr>
	<tr class="media" <if condition="$vo.gtype neq 3">style="display:none;"</if>>
		<th>{%MEDIA}</th>
		<td>
		
		<ul>
		<foreach name="list" item="item">
		<li style="float:left;margin-right:20px;line-height:30px;"><label><input type="radio" <eq name="vo.media_id" value="$item.media_id">checked="checked"</eq> class="textinput requireinput" name="media_id" value="{$item.media_id}"/>{$item.title}<br><img src="http://www.zaijiahome.com/res/{$item.local_img}" width="100"></label></li>
		</foreach>
		</ul>
		</td>
	</tr>
	<tr class="content" <if condition="$vo.gtype neq 2 && $vo.is_all eq 0">style="display:none;"</if>>
		<th>{%CONTENT}</th>
		<td>
			<textarea name="content" class="textinput areainput" rows="15">{$vo.content}</textarea>
		</td>
	</tr>
	<tr class="media_new" <if condition="$vo.gtype neq 4 && $vo.is_all eq 0">style="display:none;"</if>>
		<th>{%MEDIA_NEW_OWN}</th>
		<td>
		<ul id="news_ajax">		
			<li style="float:left;margin-right:20px;margin-bottom:10px;line-height:20px;">
				<label>
					<div style="height:200px;width:190px;border:1px solid #e7e7eb">
					<foreach name="key_item" item="item_one">
					<div>
					{$item_one.title}<br>
					<if condition="$item_one.sort eq 0 && $item_one.local_img neq null">
					<img src="http://www.zaijiahome.com/res/{$item_one.local_img}" height="100">
					</if>
					</div>
					</foreach>
					</div>
				</label>
			</li>		
		</ul>
		</td>
	</tr>
	<tr class="media_new" <if condition="$vo.gtype neq 4 && $vo.is_all eq 0">style="display:none;"</if>>
		<th>{%MEDIA_NEW}</th>
		<td>
		<ul id="news_ajax">
		<foreach name="new_list" item="item">
			<li style="float:left;margin-right:20px;margin-bottom:10px;line-height:20px;">
				<label>
					<input type="radio" class="textinput requireinput" <eq name="vo.medianew_id" value="$item.id">checked="checked"</eq> name="medianew_id" value="{$item.id}"/>
					<div style="height:200px;width:190px;border:1px solid #e7e7eb">
					<foreach name="item['item']" item="item_one">
					<div>
					{$item_one.title}<br>
					<if condition="$item_one.sort eq 0 && $item_one.local_img neq null">
					<img src="http://www.zaijiahome.com/res/{$item_one.local_img}" height="100">
					</if>
					</div>
					</foreach>
					</div>
				</label>
			</li>
		</foreach>
		</ul>
		</td>
	</tr>
	<tr class="media_new" <if condition="$vo.gtype neq 4 && $vo.is_all eq 0">style="display:none;"</if>>
		<th></th>
		<td>
			<a href="javascript:void(0);" onclick="nextbtn('pre')">上一页</a>
			<a href="javascript:void(0);" onclick="nextbtn('next')">下一页</a>
			<input type="hidden" id="next_page" value="1">
			
		</td>
	</tr>

	<tr class="act">
		<th>&nbsp;</th>
		<td>
			<input type="hidden" name="id" value="{$vo.id}" />
			<input type="submit" class="submit_btn" value="{%SUBMIT}" />
			<input type="reset" class="reset_btn" value="{%RESET}" />
		</td>
	</tr>
</table>
</form>
<script>
	function changGtype(obj)
	{
		switch(obj.value)
		{
			case '1':
				$(".url").show();
				$(".media").hide();
				$(".content").hide();	
				$(".media_new").hide();	
			break;
			case '2':
				$(".url").hide();
				
				$(".content").show();
				if($("input[type='checkbox']").is(':checked')==false){
					$(".media").hide();
					$(".media_new").hide();	
				}else{
					$(".media").show();
					$(".media_new").show();	
				}
			break;
			
			case '3':
				$(".url").hide();
				$(".media").show();
				
				if($("input[type='checkbox']").is(':checked')==false){
					$(".content").hide();
					$(".media_new").hide();
				}else{
					$(".content").show();
					$(".media_new").show();	
				}
			break;
			case '4':
				$(".url").hide();
				
				$(".media_new").show();
				if($("input[type='checkbox']").is(':checked')==false){
					$(".content").hide();
					$(".media").hide();
				}else{
					$(".content").show();
					$(".media").show();	
				}
			break;
		}
		
	}
	$('#is_all').change(function(){
		if($("input[type='checkbox']").is(':checked')==false){
			$(".content").hide();
			$(".media_pic").hide();
			$(".media_new").hide();
			$(".url").hide();
		}else{
			$(".content").show();
			$(".url").hide();
			$(".media_pic").show();	
			$(".media_new").show();	
		}
	});
	function nextbtn(obj){
		var current = jQuery("#next_page").val();	
		var ajaxtype = obj;
		
		var url = "/trends/index.php?m=ServerWxkw&a=addajax";
		
		jQuery.ajax({
			url:url,
			type:"POST",
			data:{page:current,ajaxtype:ajaxtype},
			dataType:"json",
			async: false,
			success:function(result){
				
				var info = result;
				
				if(info.status==1){
					jQuery("#news_ajax").empty();
					for(var i=0;i<info.data.length;i++){
						
						var headhtml = '<li style="float:left;margin-right:20px;margin-bottom:10px;line-height:20px;"><label>\
							<input type="radio" class="textinput requireinput" name="medianew_id" value="'+info['data'][i]['id']+'"/>\
							<div style="height:200px;width:190px;border:1px solid #e7e7eb">';	
						var foothtml = '</div></label></li>';
						var mainhtml = '';
						for(var j=0;j<info['data'][i]['item'].length;j++){
							if(info['data'][i]['item'][j]['sort']==0 && info['data'][i]['item'][j]['local_img'] != null){
								var imghtml = '<img src="http://www.zaijiahome.com/res/'+info['data'][i]['item'][j]['local_img']+'" height="100">';
							}else{
								var imghtml = '';
							}
							mainhtml += '<div>'+info['data'][i]['item'][j]['title']+'<br>'+imghtml+'</div>';
						}
						
						var appendhtml = headhtml+mainhtml+foothtml;						
						jQuery("#news_ajax").append(appendhtml);
					}
					jQuery('#next_page').val(info['data'][0]['page']);
				}				
				
			},error:function (){
				
				return false;
			}
		}); 
	}
</script>
<include file="Public:footer" />